package cn.iocoder.yudao.module.product.selection.service;

import cn.iocoder.yudao.framework.business.basic.dao.query.CoreQueryWrapper;
import cn.iocoder.yudao.framework.business.basic.service.CrudService;
import cn.iocoder.yudao.framework.business.basic.service.impl.BaseService;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.product.selection.dao.ProductSupplySelectionMapper;
import cn.iocoder.yudao.module.product.selection.pojo.po.ProductSupplySelection;
import cn.iocoder.yudao.module.product.selection.pojo.vo.ProductSupplySelectionQueryDTO;
import cn.iocoder.yudao.module.product.selection.pojo.vo.ProductSupplySelectionSaveDTO;
import cn.iocoder.yudao.module.product.selection.pojo.vo.ProductSupplySelectionVO;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/03/11
 */
@Validated
@Service
public class ProductSupplySelectionServiceImpl extends BaseService<ProductSupplySelection, ProductSupplySelectionVO, ProductSupplySelectionQueryDTO> implements ProductSupplySelectionService, CrudService<ProductSupplySelection, ProductSupplySelectionVO, ProductSupplySelectionSaveDTO, ProductSupplySelectionQueryDTO> {
    @Resource
    private ProductSupplySelectionMapper productSupplySelectionMapper;

    @Override
    public ProductSupplySelectionMapper getInjectedMapper() {
        return productSupplySelectionMapper;
    }

    @Override
    public ProductSupplySelection convertToEntity(ProductSupplySelectionSaveDTO param) {
        return BeanUtils.toBean(param, ProductSupplySelection.class);
    }

    @Nonnull
    @Override
    protected CoreQueryWrapper<ProductSupplySelection> buildQueryWrapper(ProductSupplySelectionQueryDTO param) {
        CoreQueryWrapper<ProductSupplySelection> wrapper = super.buildQueryWrapper(param);
        String columns = "id, source, spu_id, spu_name, spu_pic_url, spu_3rd_link, category_id, category_name, brand_id, brand_name, unit_name, multi_spec, cost_price, market_price, stock, profit_percent, discount, sku_ids, status, create_time";
        if (Boolean.TRUE.equals(param.getIncludeSnapshot())) {
            columns += ", update_time, snapshot";
        }
        wrapper.select(columns);
        wrapper.eqIfPresent("source", param.getSource());
        wrapper.eqIfPresent("spu_id", param.getSpuId());
        wrapper.eqIfPresent("category_id", param.getCategoryId());
        wrapper.eqIfPresent("brand_id", param.getBrandId());
        wrapper.eqIfPresent("status", param.getStatus());
        wrapper.eqIfPresent("multi_spec", param.getMultiSpec());
        return wrapper;
    }

}
